package com.desarrolladoresandroid.libgdx.models;

import com.desarrolladoresandroid.libgdx.demo1.Assets;

public class World {
	
	public boolean isFinished;
	
	public Ball ball;
	public Bar bar;
	public Lad lad;
	
	public World(){
		initialize();
	}
	
	public void initialize(){
		ball = new Ball(10f / 2, 6);
		bar = new Bar(4, 1);
		lad = new Lad(3,12);
		isFinished = false;
	}
	
	public void update(float delta){ //actualiza el mundo
		ball.position.add(ball.direction.x * delta, ball.direction.y * delta,0);
		
		
		
		//choque en pared derecha
		if(ball.position.x + 0.25 > 9){
			ball.position.x = 9 - 0.25f;
			ball.direction.x = -ball.VELOCITY;
			Assets.jump.play(1);
		}
		
		//choque en pared superior
		if(ball.position.y + 0.25 > 14){
			ball.position.y = 14 - 0.25f;
			ball.direction.y=-ball.VELOCITY;
			Assets.jump.play(1);
		}
		
		//choque en pared izquierda
		if(ball.position.x - 0.25 < 1){
			ball.position.x = 1 + 0.25f;
			ball.direction.x = ball.VELOCITY;
			Assets.jump.play(1);
		}
		
		//choque barra
		if(ball.position.y < 1 + 0.25 ){
			if(ball.position.x > bar.position.x && ball.position.x < bar.position.x + 2){
				ball.position.y = 1+0.25f;
				ball.direction.y = ball.VELOCITY;
				Assets.jump.play(1);
			}
		}
			
		//choque con ladrillo
		if(ball.position.y + 0.25 > lad.position.y && ball.position.y - 0.25 < lad.position.y){
			if(ball.position.x+0.25 > lad.position.x && ball.position.x - 0.25 < lad.position.x + 2){
				lad.Eliminado();
				System.out.println("eliminado");
			}
		}
			
		//te matan
		if(ball.position.y < 0.25f){
			isFinished = true;
		}
		
		
	}
}
